<template>
  <div class="alll">
    <img :src="deletee" @click="deleteee" class="imgg" />
    <div class="showw" @click="changelike">
      <img :src="img" class="imgg" />
    </div>
    <el-dialog title="提示" :visible="dialogVisible">
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      img: require("@/assets/dislike.png"),
      deletee: require("@/assets/no.png"),
      dialogVisible: false,
    };
  },
  props: ["avid", "userid", "category"],
  mounted() {
    var that = this;
    this.axios
      .get("http://120.78.199.38:9000/judgeActivity", {
        params: {
          avid: that.avid,
          userid: that.$store.state.yb_userid,
        },
      })
      .then((res) => {
        console.log(res);
        if (res.data == true) {
          that.img = require("@/assets/like.png");
        }
      });
  },
  methods: {
    deleteee() {
      var that = this;
      this.$confirm("确认删除？")
        .then((_) => {
          //loading
          const loading = this.$loading({
            lock: true,
            text: "拼命删除中.......",
            spinner: "el-icon-loading",
            background: "rgba(0, 0, 0, 0.7)",
          });
          this.axios
            .get("http://120.78.199.38:9000/activity/deleteMineActivity", {
              params: {
                actid: that.avid,
                userid: that.userid,
                category: that.category,
              },
            })
            .then((res) => {
              //子传父
              that.$emit("getNewmsg", res.data);
              loading.close();
            });
        })
        .catch((_) => {});
    },
    changelike() {
      var that = this;
      if (this.img == require("@/assets/dislike.png")) {
        const loading = this.$loading({
          lock: true,
          text: "Loading",
          spinner: "el-icon-loading",
          background: "rgba(0, 0, 0, 0.7)",
        });
        //关注
        this.axios
          .get("http://120.78.199.38:9000/loveActivity", {
            params: {
              avid: that.avid,
              userid: that.$store.state.yb_userid,
            },
          })
          .then((res) => {
            loading.close();
            this.$message({
              message: "关注成功",
              type: "success",
            });
            this.img = require("@/assets/like.png");
            // console.log(res.data);
          });
      } else {
        const loading = this.$loading({
          lock: true,
          text: "Loading",
          spinner: "el-icon-loading",
          background: "rgba(0, 0, 0, 0.7)",
        });
        //取关
        this.axios
          .get("http://120.78.199.38:9000/deleteActivity", {
            params: {
              avid: that.avid,
              userid: that.$store.state.yb_userid,
            },
          })
          .then((res) => {
            this.img = require("@/assets/dislike.png");
            loading.close();
            // console.log(res.data);
          });
      }
    },
  },
};
</script>
<style>
.alll {
  height: 100%;
  width: 10%;
}
.imgg {
  height: 25px;
  width: 25px;
  position: relative;
  left: 0px;
  top: 15px;
}
.showw {
  height: 55px;
  width: 100%;
  position: relative;
  top: 40%;
}
.el-message-box {
  width: 100%;
  position: absolute;
  bottom: 0px;
  left: 0px;
}
</style>
